package ca.nfb.media.nfbPlayer.ui
{
	import ca.nfb.media.nfbPlayer.ComModule;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import gs.TweenLite;
	
	public class PlaylistImage extends MovieClip
	{
		public var imageHolder	:NFBImage 	= new NFBImage(135, 76);
		private var _data		:Object 	= new Object();
		
		
		public function PlaylistImage(data:Object)
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE, addedToStage, false, 0, true);
			_data = data;
		}
		
		private function addedToStage(evt:Event):void
		{
			imageHolder.addEventListener(NFBImage.IMAGE_LOADED, imageLoaded, false, 0, true);
			imageHolder.addEventListener(NFBImage.IMAGE_LOADING, imageLoading, false, 0, true);
			loadImage();
		}
		
		public function clear():void
		{
			imageHolder.clear();
			if (MovieClip(thumbHolder_mc).contains(imageHolder))
				MovieClip(thumbHolder_mc).removeChild(imageHolder);
		}
		
		private function imageLoaded(evt:Event):void
		{
			thumbHolder_mc.addChild(imageHolder);
			
			this.useHandCursor = true;
			this.mouseEnabled = true;
			this.buttonMode = true;
			this.addEventListener(MouseEvent.MOUSE_OVER, mOver, false, 0, true);
			this.addEventListener(MouseEvent.MOUSE_OUT, mOut, false, 0, true);
			this.addEventListener(MouseEvent.CLICK, clicked, false, 0, true);
			// TabIndexManager.appendGrouppedTabItems(this.name, [this]); 
			TweenLite.to(this, .2, {alpha:.7});		
			// ComModule.getInstance().core.screenReaderManager.addAccess(this, String(_data['title']+" "+_data['director']), String(_data['title']+" "+_data['director']) ); 
		}
		
		private function imageLoading(evt:Event):void
		{
			
		}
		
		public function loadImage():void
		{
			this.addChild(imageHolder);
			// imageHolder.startLoading(yourImageURL);
		}
		
		private function mOver(evt:MouseEvent):void
		{
			TweenLite.to(this, .2, {alpha:1});
			// ComModule.getInstance().core.playlistOver.show(_data, this);
			
		}
		
		private function mOut(evt:MouseEvent):void
		{
			TweenLite.to(this, .2, {alpha:.7});
			if (!ComModule.getInstance().core.playlistOver.showing)
				ComModule.getInstance().core.playlistOver.hide();
			// ComModule.getInstance().core.toolTip.hideToolTip();
		}
		
		private function clicked(evt:MouseEvent):void
		{
			/* ComModule.getInstance().core.player.stop();
			ComModule.getInstance().core.showPreviewImage = false;
			ComModule.getInstance().core.showWarningMessages = false;
			ComModule.getInstance().core.setCurrentState(NFBPlayer.DEFAULT_STATE);
			ComModule.getInstance().core.toolTip.hideToolTip(); */
		}
		
		
	}
}